<template>
  <div class="msg-detail-bg">
    <div class="msg-detail-header">
      <el-button link class="back-btn" @click="goBack">
        <el-icon><ArrowLeft /></el-icon>
      </el-button>
      <span class="msg-detail-title">消息详情</span>
      <span class="msg-detail-status">
        <span v-if="!msg.read" class="dot-unread"></span>
        <span v-if="!msg.read" class="status-text">未读</span>
      </span>
    </div>
    <div class="msg-detail-main">
      <el-card class="msg-main-card">
        <div class="msg-main-header">
          <el-avatar :size="48" :src="msg.avatar" />
          <div class="msg-main-user">
            <div class="msg-main-name">{{ msg.user }}</div>
            <el-tag :type="msg.roleTagType" size="small">{{ msg.role }}</el-tag>
          </div>
          <div class="msg-main-time">{{ msg.datetime }}</div>
        </div>
        <div class="msg-main-content">
          <div class="msg-main-text" v-html="msg.content"></div>
          <ul v-if="msg.list && msg.list.length" class="msg-main-list">
            <li v-for="(item, idx) in msg.list" :key="idx">{{ item }}</li>
          </ul>
        </div>
        <el-card class="msg-task-card" v-if="msg.task">
          <div class="msg-task-title">{{ msg.task.title }}</div>
          <div class="msg-task-id">任务编号：{{ msg.task.id }}</div>
        </el-card>
        <div class="msg-main-extra">
          <el-icon><View /></el-icon>
          已读 {{ msg.readCount }} 人
        </div>
      </el-card>
      <el-card class="msg-relate-card">
        <div class="relate-title">相关人员</div>
        <div class="relate-list">
          <div v-for="(person, idx) in msg.related" :key="idx" class="relate-item">
            <el-avatar :size="36" :style="{ background: person.bg }">{{ person.avatarText }}</el-avatar>
            <div class="relate-info">
              <div class="relate-name">{{ person.name }}</div>
              <div class="relate-role">{{ person.role }}</div>
            </div>
          </div>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ArrowLeft, View } from '@element-plus/icons-vue'

const router = useRouter()
const route = useRoute()
const goBack = () => router.back()

// 假数据，实际可用store或API
const msgList = [
  {
    id: '1',
    user: '张建国',
    avatar: 'https://randomuser.me/api/portraits/men/32.jpg',
    role: '工长',
    roleTagType: 'success',
    datetime: '2024-01-18 14:30',
    read: false,
    content: '各位工友注意，明天上午9点在A区三楼进行安全培训，请准时参加。培训内容包括：',
    list: ['新设备操作规程', '安全防护措施', '应急处理流程'],
    task: { title: '安全培训任务', id: 'TRAIN-20240118-001' },
    readCount: 12,
    related: [
      { name: '李明远', role: '工人', bg: '#b7eb8f', avatarText: '李' },
      { name: '王海涛', role: '工人', bg: '#ffd591', avatarText: '王' }
    ]
  }
]
const msg = ref(msgList.find(m => m.id === route.params.id) || msgList[0])
</script>

<style scoped>
.msg-detail-bg {
  background: #f5f7fa;
  min-height: 100vh;
  padding-bottom: 32px;
}
.msg-detail-header {
  display: flex;
  align-items: center;
  padding: 18px 32px 0 32px;
  background: #f5f7fa;
}
.back-btn {
  font-size: 1.1em;
  color: #409EFF;
  padding: 0;
  margin-right: 12px;
}
.msg-detail-title {
  flex: 1;
  text-align: center;
  font-size: 1.1em;
  font-weight: bold;
  color: #222;
}
.msg-detail-status {
  display: flex;
  align-items: center;
  gap: 6px;
}
.dot-unread {
  width: 10px;
  height: 10px;
  background: #f56c6c;
  border-radius: 50%;
  display: inline-block;
}
.status-text {
  color: #f56c6c;
  font-size: 1em;
}
.msg-detail-main {
  max-width: 900px;
  margin: 0 auto;
  padding: 18px 0 0 0;
}
.msg-main-card {
  margin-bottom: 18px;
  border-radius: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  border: 1px solid #f2f2f2;
}
.msg-main-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 8px;
}
.msg-main-user {
  display: flex;
  align-items: center;
  gap: 8px;
}
.msg-main-name {
  font-weight: 600;
  color: #222;
}
.msg-main-time {
  margin-left: auto;
  color: #999;
  font-size: 0.98em;
}
.msg-main-content {
  margin-bottom: 10px;
}
.msg-main-text {
  color: #444;
  font-size: 1em;
  margin-bottom: 6px;
}
.msg-main-list {
  margin: 0 0 8px 0;
  padding-left: 18px;
  color: #444;
  font-size: 1em;
}
.msg-task-card {
  background: #f7f8fa;
  border-radius: 8px;
  margin-bottom: 10px;
  border: none;
}
.msg-task-title {
  font-weight: 600;
  color: #222;
  font-size: 1em;
}
.msg-task-id {
  color: #999;
  font-size: 0.97em;
}
.msg-main-extra {
  color: #999;
  font-size: 0.97em;
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.msg-relate-card {
  border-radius: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  border: 1px solid #f2f2f2;
}
.relate-title {
  font-weight: 600;
  color: #222;
  font-size: 1.05em;
  margin-bottom: 10px;
}
.relate-list {
  display: flex;
  gap: 18px;
  margin-bottom: 8px;
}
.relate-item {
  display: flex;
  align-items: center;
  gap: 10px;
}
.relate-info {
  display: flex;
  flex-direction: column;
}
.relate-name {
  font-weight: 500;
  color: #222;
}
.relate-role {
  color: #888;
  font-size: 0.97em;
}
@media (max-width: 600px) {
  .msg-detail-header {
    padding: 12px 8px 0 8px;
  }
  .msg-detail-main {
    max-width: 100vw;
    padding: 12px 0 0 0;
  }
  .msg-main-card, .msg-relate-card {
    border-radius: 10px;
  }
}
</style> 